# -*- encoding:utf-8 -*-
import random

# from flask import Flask
import time

import datetime

import EmailUtil
from commons import *
from constants import *

def ngrok_health(url):
    try:
        result = requests.get(url)
        print(result)
        if result.status_code == 404:
            EmailUtil.send_mail(
                ["gaojing1996@vip.qq.com"],
                "ngrok挂了",
                "ngrok挂了",
                []
            )
            return -1
        pass
    except (Exception, RuntimeError, TypeError, NameError):
        print("内部异常，请检查服务连通")
    except:
        print("未知异常")


if __name__ == '__main__':
    urls = ["http://bill.api.ng.scare.ml/bill/health", "http://yto.207.ng.gnosis.gq"]
    while True:
        if ngrok_health(urls[0]) == -1:
            time.sleep(10)
        else:
            time.sleep(5)
